package com.example.school.controller.admin;

import com.example.school.dto.AdminGetListDto;
import com.example.school.dto.AdminSaveNotifyDto;
import com.example.school.dto.AdminUpdateNotifyDto;
import com.example.school.service.NotifyService;
import com.example.school.utils.common.enums.Code;
import com.example.school.utils.common.result.Result;
import com.example.school.utils.config.BaseContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/admin/notify")
public class AdminNotifyController {

    @Autowired
    private NotifyService notifyService;

    @PostMapping("/get_notify_list")
    public Result getNotifyList(@RequestBody AdminGetListDto dto){
        return notifyService.getNotifyList(dto);
    }

    @PostMapping("/save_notify")
    public Result saveNotify(@RequestBody AdminSaveNotifyDto dto){
        return notifyService.saveNotify(dto);
    }

    @GetMapping("/remove_notify")
    public Result removeNotify(@RequestParam("id")Long id){
        return notifyService.removeNotify(id);
    }

    @GetMapping("/update_get_notify")
    public Result updateGetNotify(@RequestParam("id")Long id){
        if (BaseContext.getCurrentId()==null) {
            return Result.errorResult(Code.NEED_LOGIN);
        }
        return Result.okResult(notifyService.getById(id));
    }

    @PostMapping("/update_notify")
    public Result updateNotify(@RequestBody AdminUpdateNotifyDto dto){
        return notifyService.updateNotify(dto);
    }

}
